package iceworld.fernado.entity;

import iceworld.fernado.consts.Constants;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Table implements IEntity, Comparable<Table> {

	private static final long serialVersionUID = 1L;
	private String name;
	private String comment;
	private List<Field> fields = Collections.synchronizedList(new ArrayList<Field>());
	public Table(String name) {
		super();
		this.name = name;
	}
	
	@Override
	public String toString() {
		StringBuilder result = new StringBuilder();
		result.append("Table{");
		result.append("name=").append(name);
		for (Field field: fields) {
			result.append(Constants.SPACE).append(field).append(Constants.SPACE);
		}
		result.append("}");
		return result.toString();
	}
	public String getComment() {
		return comment;
	}
	public void setComment(String comment) {
		this.comment = comment;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public List<Field> getFields() {
		return fields;
	}
	public void setFields(List<Field> fields) {
		this.fields = fields;
	}
	public void addField(Field field) {
		fields.add(field);
	}
	public void removeField(Field field) {
		fields.remove(field);
	}
	@Override
	public int compareTo(Table o) {
		return o.name.equals(name) ? 0 : 1;
	}
}
